package tas.co.in.controller.customerinfo;

import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import tas.co.in.dao.customerinfo.CustomerInfoConnect;
import tas.co.in.domain.customerinfo.CustomerInfoBean;
import tas.co.in.domain.customerinfo.CustomerRequestBean;

public class CustomerInfoController extends MultiActionController {

	private CustomerInfoConnect customerInfoConnect;

	/**
	 * @param customerInfoConnect
	 *            the customerInfoConnect to set
	 */
	public void setCustomerInfoConnect(CustomerInfoConnect customerInfoConnect) {
		this.customerInfoConnect = customerInfoConnect;
	}

	public ModelAndView getBufferDetails(HttpServletRequest request,
			HttpServletResponse response) {

		List<CustomerInfoBean> resultObject = customerInfoConnect
				.getBufferCustomers();

		return new ModelAndView("customerJSP/BufferCustomerInfo",
				"resultObject", resultObject);

	}

	public ModelAndView customerRegistrations(HttpServletRequest request,
			HttpServletResponse response) {

		HttpSession session = request.getSession(true);

		CustomerInfoBean bean = new CustomerInfoBean();

		bean.setUserId(session.getAttribute("userId").toString());
		bean.setUsername(session.getAttribute("userName").toString());
		bean.setRoleId(session.getAttribute("roleId").toString());

		StringTokenizer items = new StringTokenizer(request
				.getParameter("selectedCustomers"), ",");

		boolean resultObject = customerInfoConnect.registerCustomers(items,
				bean);

		return new ModelAndView("sharedJSP/BooleanResults", "resultObject",
				resultObject);

	}

	public ModelAndView getRegisteredCustomers(HttpServletRequest request,
			HttpServletResponse response) {

		HttpSession session = request.getSession(true);

		CustomerInfoBean bean = new CustomerInfoBean();

		bean.setUserId(session.getAttribute("userId").toString());
		bean.setUsername(session.getAttribute("userName").toString());
		bean.setRoleId(session.getAttribute("roleId").toString());		

		List<CustomerInfoBean> resultObject = customerInfoConnect
				.getRegCustomerList();

		return new ModelAndView("customerJSP/CustomerInfo",
				"resultObject", resultObject);

	}
	
	public ModelAndView setBufferCustInfo(HttpServletRequest request, HttpServletResponse response)
	{
		HttpSession session = request.getSession(true);
		
		CustomerInfoBean bean = new CustomerInfoBean();
		bean.setUserId(session.getAttribute("userId").toString());
		bean.setUsername(session.getAttribute("userName").toString());
		bean.setRoleId(session.getAttribute("roleId").toString());
		bean.setPhoneNumber(request.getParameter("phoneNo"));
		bean.setCustomerName(request.getParameter("custName"));
		bean.setDob(request.getParameter("dob"));
		bean.setGender(request.getParameter("gender"));
		bean.setAddress(request.getParameter("address"));
		bean.setCity(request.getParameter("city"));
		bean.setState(request.getParameter("state"));
		bean.setCountry(request.getParameter("country"));
		bean.setZipcode(request.getParameter("zipcode"));
		bean.setCustomerImage(request.getParameter("imgPath"));
		bean.setCustomerPanImage(request.getParameter("panImgPath"));
		bean.setVoicePath(request.getParameter("voicePath"));
		bean.setGeoLongitude(request.getParameter("geoLong"));
		bean.setGeoLatitude(request.getParameter("geoLati"));
		bean.setImieNumber(request.getParameter("imei"));
		bean.setEmailId(request.getParameter("emailID"));
		bean.setAccountBal(request.getParameter("accBal"));
		
		boolean resultObject = customerInfoConnect.setBufferCustInfo(bean);
		return new ModelAndView("sharedJSP/BooleanResults", "resultObject", resultObject);
	}
	
	 public ModelAndView getRequests(HttpServletRequest request,
			   HttpServletResponse response)
			 {
			  CustomerRequestBean bean=new CustomerRequestBean();
			  bean.setReqCity(request.getParameter("reqCity"));
			  bean.setReqState(request.getParameter("reqState"));
			  bean.setReqStatus(request.getParameter("status"));
			  
			  List<CustomerRequestBean> resultList=customerInfoConnect.getAllRequests(bean);
			  
			  return new ModelAndView(
			    "customerJSP/BufferCustomerRequest","resultObject",resultList);
			 }
	 public ModelAndView getCustomerInfo(HttpServletRequest request,
			   HttpServletResponse response)
			 {
			  CustomerInfoBean bean=new CustomerInfoBean();
			  bean.setPhoneNumber(request.getParameter("phoneNo"));
			  
			  CustomerInfoBean resultObject=customerInfoConnect.getCustomers(bean);
			  
			  return new ModelAndView("sharedJSP/custumerInfo","resultObject",resultObject);
			  
			 }
	 
	 public ModelAndView save(HttpServletRequest request,HttpServletResponse response)
	 {
	  CustomerInfoBean bean=new CustomerInfoBean();
	  bean.setAccountNumber(request.getParameter("account"));
	  bean.setPhNumber(request.getParameter("phno"));
	  bean.setCustomerId(request.getParameter("ci"));
	  bean.setCustomerName(request.getParameter("cname"));
	  bean.setDetail(request.getParameter("det"));
	  bean.setNarration(request.getParameter("n"));
	  bean.setCombo(request.getParameter("req"));
	  Boolean resultObject=customerInfoConnect.save(bean);
	  return new ModelAndView("sharedJSP/BooleanResults","resultObject",resultObject);
	 }
	 public ModelAndView check(HttpServletRequest request,HttpServletResponse response)
	 {
	  CustomerInfoBean bean = new CustomerInfoBean();
	  bean.setAccountNumber(request.getParameter("value"));
	  List<CustomerInfoConnect> resultObject = customerInfoConnect.check(bean);
	  return new ModelAndView("sharedJSP/check", "resultObject", resultObject);
	 }
	 public ModelAndView senddata(HttpServletRequest request, HttpServletResponse response)
	 {
	  CustomerInfoBean bean =new CustomerInfoBean();
	  bean.setPhNumber(request.getParameter("mb"));
	  bean.setCustomerName(request.getParameter("cn"));
	  bean.setAddress(request.getParameter("ad"));
	  bean.setCity(request.getParameter("ci"));
	  bean.setState(request.getParameter("st"));
	  bean.setNarration(request.getParameter("na"));
	  bean.setEmailId(request.getParameter("e"));
	  Boolean resultObject= customerInfoConnect.senddata(bean);
	  return new ModelAndView("sharedJSP/BooleanResults","resultObject",resultObject);
	 }
	 public ModelAndView proedit(HttpServletRequest request,HttpServletResponse response)
	 {
	  List<CustomerInfoBean> resultObject= customerInfoConnect.proedit();
	  return new ModelAndView("sharedJSP/fetch","resultObject",resultObject);
	 }
	 
	 public ModelAndView getData(HttpServletRequest request,HttpServletResponse response)
	 {
	  List<CustomerInfoBean> resultObject= customerInfoConnect.getData();
	  return new ModelAndView("sharedJSP/getdetails","resultObject",resultObject);
	 }
}
